export function numberFormatter(num: number, lang = 'en') {
  if (lang!== 'zh' && lang!== 'en') {
    return num.toString();
  }

  if (num < 1000) {
    return num.toString();
  } else {
    if (lang === 'zh') {
      if (num >= 1000 && num < 10000) {
        return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
      } else if (num >= 10000 && num < 100000000) {
        return myToFixed(num / 10000) + ' 万';
      } else if (num >= 100000000) {
        return myToFixed(num / 100000000) + ' 亿';
      }
    } else if (lang === 'en') {
      if (num >= 1000 && num < 10000) {
        return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
      } else if (num >= 10000 && num < 1000000) {
        return myToFixed(num / 1000) + 'k';
      } else if (num >= 1000000 && num < 1000000000) {
        return myToFixed(num / 1000000) + 'm';
      } else if (num >= 1000000000) {
        return myToFixed(num / 1000000000) + 'b';
      }
    }
  }
}

function myToFixed (num: number) {
  let formattedNumber = num.toFixed(1);
  let decimalPart = formattedNumber % 1;
  if (decimalPart === 0 || decimalPart < 0.1) {
    return Math.floor(num);
  } else {
    return formattedNumber;
  }
}